package com.open.loan.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.open.loan.utils.ResponseUtil;
import com.open.system.domain.LoanApplyDO;
import com.open.system.domain.LoanUserDO;
import com.open.system.service.LoanApplyService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/moblie")
public class VueAuthGetController {
	
	@Autowired
	private LoanApplyService loanApplyService;
	
	@ApiOperation(value="信息认证,联系人认证,银行卡,人脸认证,征信认证,支付宝认证，信用卡认证(0 待完善,1 审核中,2,认证成功 3,认证失败)", notes="")
	@RequestMapping(value ="/getAuthCode",method = RequestMethod.GET)
	public ResponseEntity<String> getUserAuthInfo(HttpServletRequest request,HttpServletResponse response){
				Map<String,String>map=new HashMap<String,String>();	
				Map<String, Object> params=new HashMap<String, Object>();
				try{
					HttpSession session = request.getSession();
					LoanUserDO loanUserDo=(LoanUserDO) session.getAttribute("loanUserDo");
					if(loanUserDo==null){
						ResponseUtil.toWrite("100","请重新登录",null, response);
						return null;
					}
					params.put("userId", loanUserDo.getId());
					List<LoanApplyDO>loanApplyDOs=loanApplyService.list(params);
					LoanApplyDO applyDO=new LoanApplyDO();
					if(loanApplyDOs!=null && loanApplyDOs.size()>0){
						for (int i = 0; i < loanApplyDOs.size(); i++) {
							applyDO=loanApplyDOs.get(0);
							map.put("userAuth",applyDO.getUserInfoAuth());
							map.put("contactAuth",applyDO.getContactAuth());
							map.put("bankAuth",applyDO.getBankAuth());
							map.put("faceAuth",applyDO.getFaceAuth());
							map.put("creditAuth",applyDO.getCreditAuth());
							map.put("faceAuthReason",applyDO.getLoanScore()!=null?applyDO.getLoanScore():"0");
							map.put("alipayAuth", applyDO.getBillingtype()!=null?applyDO.getBillingtype():"0");
							map.put("creditCardAuth", applyDO.getBillingtypeCard()!=null?applyDO.getBillingtypeCard():"0");
						}
					}else {
						map.put("userAuth", "0");
						map.put("contactAuth", "0");
						map.put("bankAuth", "0");
						map.put("faceAuth","0");
						map.put("creditAuth", "0");
						map.put("faceAuthReason","");
						map.put("alipayAuth", applyDO.getBillingtype());
						map.put("creditCardAuth", applyDO.getBillingtypeCard());
					}
				} catch (Exception e) {
					e.printStackTrace();
					ResponseUtil.toWrite("202","获取信息失败",null, response);
					return null;
				}
				ResponseUtil.toWrite("200","获取信息成功",map, response);
				return null;
		}
	
}
